<?php
class model_newagk_basicuser extends gdl_components_basemodel 
{

    public function primarykey() {
        return 'id';
    }

    public function tableName() {
        return 'agk_basic_user';
    }

	public function userAdd($basicid,$userid=[]) {
		/**获取已在考场用户id**/
		$userids = explode(',',$userid);
		$identity_id = $this->basicuser($basicid);
		/**获取已在考场用户id end**/
		$basicUserId = [0];
		foreach($userids as $v){
			$basicUserId[] = intval($v);
		}
		$usercompany = new model_newagk_usercompany();
		$ucentermember = new model_newagk_user();
		$leftJoin = array(
				$ucentermember->tableName().' as c' => $usercompany->tableName().'.userId=c.userId',

			);
		$field = $usercompany->tableName().'.id,'.$usercompany->tableName().'.gdlUserId,'.$usercompany->tableName().'.platformId,'.$usercompany->tableName().'.companyId,'.$usercompany->tableName().'.companyName,c.username,c.realName,c.idcard,c.mobile';
		$cind = $usercompany->tableName().'.id in('.implode(',',$basicUserId).') and '.$usercompany->tableName().'.id not in('.implode(',',$identity_id).')';
		$res = $usercompany->select($cind, $field,'', '', $leftJoin)->items;
                gdl_lib_BaseUtils::addLog(json_encode($usercompany));

		 if (!empty($res)){
            $value_str = '';
			$datime = date('Y-m-d H:i:s');
            foreach($res as $v){
                $value_str .= "(".$v['id'].",".$v['platformId'].",'".$v['username']."',".$basicid.",'".$v['realName']."',".$v['companyId'].",'".$v['companyName']."','".$v['idcard']."','".$v['mobile']."','{$datime}','{$datime}'),";
            }
            $valueStr = rtrim($value_str,',');
            $sql2 = "INSERT into ".$this->tableName()."(identity_id,eventid,username,basic_id,usertruename,company_id,company,idcard,phone,create_time,update_time) values $valueStr";
            gdl_lib_BaseUtils::addLog($sql2);
			
            $this->query($sql2);
        }
		return true;
	}
	
	public function getInfoArg($arrg,$field)
    {
        return $this->select($arrg, $field)->items;
    }
	public function getInfoArgOne($arrg=[],$field)
    {
		if(empty($arrg)) return false;
		return $this->selectOne($arrg, $field);
    }
	//获取考场人员
	public function basicuser($basicid)
    {
       $identity_id = $this->getInfoArg('basic_id='.$basicid, 'identity_id');
	   $userid = [0];
	   foreach($identity_id as $v){
		   $userid[] = $v['identity_id'];
	   }
	   return $userid;
    }
	
	//人员所在考场
	public function basicid($identity_id,$staus = 0)
    {
		$basic = $this->getInfoArg('identity_id='.$identity_id, 'basic_id');
		$basic_id = [0];
		   foreach($basic as $v){
			   $basic_id[] = $v['basic_id'];
		   }
		
		return $staus ? implode(',',$basic_id) : $basic_id;
    }
	
}
